package com.xiechur.service.impl;

import com.xiechur.dao.BankDao;
import com.xiechur.service.BankService;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by dell on 2016/3/28.
 */
@Transactional
//有了这个就不用在beans.xml中写事务通知，事务模式了，但要<tx:annotation-driven transaction-manager="transactionManager"/>

public class BankServiceImpl implements BankService {
    private BankDao bankDao;

//    private TransactionTemplate transactionTemplate;

//    public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
//        this.transactionTemplate = transactionTemplate;
//    }

    public void setBankDao(BankDao bankDao) {
        this.bankDao = bankDao;
    }

    @Override
    public void transferAccounts(int count, int userIdA, int userIdB) {
        bankDao.outMoney(count, userIdA);
        bankDao.inMoney(count, userIdB);
    }

//    @Override
//    public void transferAccounts(final int count, final int userIdA, final int userIdB) {
//        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//            @Override
//            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//                bankDao.outMoney(count,userIdA);
//                bankDao.inMoney(count,userIdB);
//            }
//        } );
//  这样写不好
//    }
}
